import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class SettingsMenu extends JPopupMenu{
	private static final long serialVersionUID = 1L;
	
	String i1 = "icon1.jpg";
	String i2 = "icon2.jpg";
	String i3 = "icon3.jpg";
	String i4 = "icon4.jpg";
	String i5 = "icon5.jpg";
	String i6 = "icon6.jpg";
	
	public SettingsMenu(){
		super("Settings");
		setVisible(false);
		setPreferredSize(new Dimension(400,500));
		
		JPanel settingsPanel = new JPanel();
		settingsPanel.setLayout(null);
		JLabel nameLabel = new JLabel("Name:");
		JTextField name = new JTextField();
		JLabel imageSelect = new JLabel("Select an Icon:");
		JPanel imageSelectPanel = new JPanel();
		imageSelectPanel.setLayout(new BorderLayout());
		
		JPanel imagePanel = new JPanel();
		final JPanel imageSelectPanel1 = new JPanel();
		final JPanel imageSelectPanel2 = new JPanel();
		final JPanel imageSelectPanel3 = new JPanel();
		final JPanel imageSelectPanel4 = new JPanel();
		final JPanel imageSelectPanel5 = new JPanel();
		final JPanel imageSelectPanel6 = new JPanel();
		
		imageSelectPanel1.setLayout(new BorderLayout());
		imageSelectPanel2.setLayout(new BorderLayout());
		imageSelectPanel3.setLayout(new BorderLayout());
		imageSelectPanel4.setLayout(new BorderLayout());
		imageSelectPanel5.setLayout(new BorderLayout());
		imageSelectPanel6.setLayout(new BorderLayout());
		
		ImageIcon image1 = new ImageIcon(getClass().getResource(i1));
		ImageIcon image2 = new ImageIcon(getClass().getResource(i2));
		ImageIcon image3 = new ImageIcon(getClass().getResource(i3));
		ImageIcon image4 = new ImageIcon(getClass().getResource(i4));
		ImageIcon image5 = new ImageIcon(getClass().getResource(i5));
		ImageIcon image6 = new ImageIcon(getClass().getResource(i6));
		
		final JButton selectImage1 = new JButton("Select");
		JButton selectImage2 = new JButton("Select");
		JButton selectImage3 = new JButton("Select");
		JButton selectImage4 = new JButton("Select");
		JButton selectImage5 = new JButton("Select");
		JButton selectImage6 = new JButton("Select");
		
		imageSelectPanel1.add(new JLabel(image1), BorderLayout.CENTER);
		imageSelectPanel1.add(selectImage1, BorderLayout.SOUTH);
		imageSelectPanel2.add(new JLabel(image2), BorderLayout.CENTER);
		imageSelectPanel2.add(selectImage2, BorderLayout.SOUTH);
		imageSelectPanel3.add(new JLabel(image3), BorderLayout.CENTER);
		imageSelectPanel3.add(selectImage3, BorderLayout.SOUTH);
		imageSelectPanel4.add(new JLabel(image4), BorderLayout.CENTER);
		imageSelectPanel4.add(selectImage4, BorderLayout.SOUTH);
		imageSelectPanel5.add(new JLabel(image5), BorderLayout.CENTER);
		imageSelectPanel5.add(selectImage5, BorderLayout.SOUTH);
		imageSelectPanel6.add(new JLabel(image6), BorderLayout.CENTER);
		imageSelectPanel6.add(selectImage6, BorderLayout.SOUTH);
		
		imagePanel.setLayout(new GridLayout(3,2,5,5));
		imagePanel.add(imageSelectPanel1);
		imagePanel.add(imageSelectPanel2);
		imagePanel.add(imageSelectPanel3);
		imagePanel.add(imageSelectPanel4);
		imagePanel.add(imageSelectPanel5);
		imagePanel.add(imageSelectPanel6);
		
		JScrollPane imagePane = new JScrollPane(imagePanel);
		
		
		JButton accept = new JButton("Accept");
		
		//Actions for the buttons
		accept.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				
			}
		});
		
		selectImage1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				imageSelectPanel1.setBorder(BorderFactory.createLineBorder(Color.yellow, 2));
				imageSelectPanel2.setBorder(null);
				imageSelectPanel3.setBorder(null);
				imageSelectPanel4.setBorder(null);
				imageSelectPanel5.setBorder(null);
				imageSelectPanel6.setBorder(null);
				revalidate();
			}
		});
		
		selectImage2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				imageSelectPanel2.setBorder(BorderFactory.createLineBorder(Color.yellow, 2));
				imageSelectPanel1.setBorder(null);
				imageSelectPanel3.setBorder(null);
				imageSelectPanel4.setBorder(null);
				imageSelectPanel5.setBorder(null);
				imageSelectPanel6.setBorder(null);
			}
		});
		
		selectImage3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				imageSelectPanel3.setBorder(BorderFactory.createLineBorder(Color.yellow, 2));
				imageSelectPanel2.setBorder(null);
				imageSelectPanel1.setBorder(null);
				imageSelectPanel4.setBorder(null);
				imageSelectPanel5.setBorder(null);
				imageSelectPanel6.setBorder(null);
			}
		});
		
		selectImage4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				imageSelectPanel4.setBorder(BorderFactory.createLineBorder(Color.yellow, 2));
				imageSelectPanel2.setBorder(null);
				imageSelectPanel3.setBorder(null);
				imageSelectPanel1.setBorder(null);
				imageSelectPanel5.setBorder(null);
				imageSelectPanel6.setBorder(null);
			}
		});
		
		selectImage5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				imageSelectPanel5.setBorder(BorderFactory.createLineBorder(Color.yellow, 2));
				imageSelectPanel2.setBorder(null);
				imageSelectPanel3.setBorder(null);
				imageSelectPanel4.setBorder(null);
				imageSelectPanel1.setBorder(null);
				imageSelectPanel6.setBorder(null);
			}
		});
		
		selectImage6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				imageSelectPanel6.setBorder(BorderFactory.createLineBorder(Color.yellow, 2));
				imageSelectPanel2.setBorder(null);
				imageSelectPanel3.setBorder(null);
				imageSelectPanel4.setBorder(null);
				imageSelectPanel5.setBorder(null);
				imageSelectPanel1.setBorder(null);
			}
		});
		
		imageSelectPanel.add(imageSelect, BorderLayout.NORTH);
		imageSelectPanel.add(imagePane, BorderLayout.CENTER);
		settingsPanel.add(nameLabel);
		settingsPanel.add(name);
		settingsPanel.add(imageSelectPanel);
		settingsPanel.add(accept);
		
		//Set bounds
		nameLabel.setBounds(100,15,50,25);
		name.setBounds(150,15,150,25);
		imageSelectPanel.setBounds(15,75,360,360);
		accept.setBounds(150,450,100,25);		
		setLocation(400,300);
		
		add(settingsPanel);
		pack();
		
	}
}
